package com.ts.crawler;

import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;

public class PhantomjsTest {

    public static void main(String[] args) {

        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        //ssl证书支持
        desiredCapabilities.setCapability("acceptSslCerts", true);
        //截屏支持，这里不需要
        desiredCapabilities.setCapability("takesScreenshot", false);
        //css搜索支持
        desiredCapabilities.setCapability("cssSelectorsEnabled", true);
        //js支持
        desiredCapabilities.setJavascriptEnabled(true);
        //驱动支持
        desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                "E:\\static\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
        //创建无界面浏览器对象
        PhantomJSDriver driver = new PhantomJSDriver(desiredCapabilities);
        //这里注意，把窗口的大小调整为最大，如果不设置可能会出现元素不可用的问题
        driver.manage().window().maximize();

        driver.get("https://flights.ctrip.com/online/list/round-SZX-BJS?_=1&depdate=2021-10-19_2021-10-23&cabin=C_F");
        String page = driver.getPageSource();
        String str = driver.findElementByXPath("//*[@id=\"__next\"]/div[2]/div/div[2]/div/div[3]/div[2]/div[2]/span/div[2]/div/div/div/div[2]/div[2]/div/text()").toString();
        System.out.println(page);

    }
}
